<template>
  <el-container>
    <el-main>
      <el-card class="box-card" style="margin:20px auto; height:300px; width:600px ;padding: 0px 50px 60px 10px">
        <div slot="header" style="margin: 10px 20px ;text-align: left">
          <span>发帖子</span>
        </div>
        <el-divider />
        <el-form ref="form" :model="form" :rules="rules" label-width="70px" style="margin: 30px 0 ; padding: 20px 60px" size="medium">
          <el-form-item label="标题">
            <el-input v-model="form.title"></el-input>
          </el-form-item>
          <el-form-item label="内容">
            <el-input type="textarea" v-model="form.bottle" ></el-input>
          </el-form-item>
          <el-form-item aria-posinset="common">
            <div style="margin: 20px 0 0 0; text-align:center;position:center" >
              <el-button type="primary" size="default" @click="onSubmit">确认</el-button>
            </div>
          </el-form-item>
        </el-form>
      </el-card>
    </el-main>
  </el-container>
</template>



<script>
import Menu from '../components/Menu.vue'
import BottleAside from "../components/BottleAside.vue";
export default {
  name: "Write",
  components: {Menu,BottleAside},
  data() {
    return {
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      form: {
        title: '',
        bottle: ''
      },
      rules: {
        title: [
          {required: true, message: "请输入用户名", trigger: "blur"},
        ],
        bottle: [
          {required: true, message: "请输入密码", trigger: "blur"},
        ],
      }
    }
  },
  methods: {
    onSubmit() {
      this.form.user = this.user.username
      this.rq.post("/bottle/add", this.form).then(res => {
        if (res.code === '200') {
          this.$message.success("添加成功")
        } else {
          this.$message.error(res.msg)
        }
      }).catch((err) => {
        this.$message.error("未知错误")
      })
    }
  }
}
</script>

<style scoped>

</style>


